﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ToolGood.Words;

namespace kis.UC
{
    public partial class BaseForm
    {
        /// <summary>
        /// 
        /// </summary>
        private Dictionary<TextBox, TextBox> JPMContrDic { get; set; } = new Dictionary<TextBox, TextBox>();

        /// <summary>
        /// 
        /// </summary>
        private Dictionary<ComboBox, TextBox> JPMContrDicV1 { get; set; } = new Dictionary<ComboBox, TextBox>();

        /// <summary>
        /// 
        /// </summary>
        /// <param name="nameBox"></param>
        /// <param name="jpmBox"></param>
        public void BindJPMEvent(TextBox nameBox, TextBox jpmBox)
        {
            this.JPMContrDic.Add(nameBox, jpmBox);

            nameBox.TextChanged += (object sender, EventArgs e) =>
            {
                var tBox = sender as TextBox;

                if (this.JPMContrDic.ContainsKey(tBox))
                {
                    string name = tBox.Text.Trim();

                    this.JPMContrDic[tBox].Text = GetJPM(name);
                }
            };
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="cBox"></param>
        /// <param name="jpmBox"></param>
        public void BindJPMEvent(ComboBox cBox, TextBox jpmBox)
        {
            this.JPMContrDicV1.Add(cBox, jpmBox);

            cBox.TextChanged += (object sender, EventArgs e) =>
            {
                var comBox = sender as ComboBox;

                if (this.JPMContrDicV1.ContainsKey(comBox))
                {
                    string name = comBox.Text.Trim();

                    this.JPMContrDicV1[comBox].Text = GetJPM(name);
                }
            };
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="strText"></param>
        /// <returns></returns>
        public string GetJPM(string strText)
        {
            return WordsHelper.GetFirstPinyin(strText);
        }
    }
}
